import { register } from '../../request/index.js';

Page({
  data: {
    username: '',
    password0: '',
    password1: ''
  },
  toLogin(){
    wx.navigateBack({
      url: '../login/login',
    })
  },
  register(){
    if(!this.data.username){
      wx.showToast({
        title: '请输入账号',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    else if(!this.data.password0){
      wx.showToast({
        title: '请输入密码',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    else if(this.data.password0 != this.data.password1){
      wx.showToast({
        title: '两次输入密码不一致',
        duration: 1000,
        icon: 'none'
      });
      return;
    }
    register({id: this.data.username, pwd: this.data.password0}).then(res => {
      if(res.message == 'ACCEPTED'){
        wx.showToast({
          title: '注册成功',
          icon: 'success',
          duration: 1000
        });
        setTimeout(() => {
          wx.navigateBack({
            delta: 0,
          })
        },600)
      }
      else{
        wx.showToast({
          title: '未知错误',
          icon: 'error'
        });
      }
    })
  }
})